package org.me.marble;

import java.nio.*;

import javax.microedition.khronos.opengles.GL10;

/**
 *
 * @author tungi
 */

public class PointObject extends AvailableObject{
    private FloatBuffer frontBuffer,backBuffer,blanketBuffer;

    public PointObject(int id){
        super(id);
    }

    @Override
    public void effect(GameRenderer _renderer,MoveMarble _mm){
        OptionsLibrary.points+=200;
    }

    @Override
    public void init(){
        //set the coordinates of this object's front side
        float[] front={0.0f,0.0f,-0.1f,
                       -0.1f,0.25f,-0.1f,
                       -0.1f,0.1f,-0.1f,
                       -0.25f,0.1f,-0.1f,
                       -0.25f,-0.1f,-0.1f,
                       -0.1f,-0.1f,-0.1f,
                       -0.1f,-0.25f,-0.1f,
                       0.1f,-0.25f,-0.1f,
                       0.1f,-0.1f,-0.1f,
                       0.25f,-0.1f,-0.1f,
                       0.25f,0.1f,-0.1f,
                       0.1f,0.1f,-0.1f,
                       0.1f,0.25f,-0.1f,
                       -0.1f,0.25f,-0.1f
        };
        float[] back={0.0f,0.0f,0.1f,
                      -0.1f,0.25f,0.1f,
                      0.1f,0.25f,0.1f,
                      0.1f,0.1f,0.1f,
                      0.25f,0.1f,0.1f,
                      0.25f,-0.1f,0.1f,
                      0.1f,-0.1f,0.1f,
                      0.1f,-0.25f,0.1f,
                      -0.1f,-0.25f,0.1f,
                      -0.1f,-0.1f,0.1f,
                      -0.25f,-0.1f,0.1f,
                      -0.25f,0.1f,0.1f,
                      -0.1f,0.1f,0.1f,
                      -0.1f,0.25f,0.1f
        };
        float[] blanket={-0.1f,0.25f,-0.1f,
                         -0.1f,0.25f,0.1f,
                         -0.1f,0.1f,-0.1f,
                         -0.1f,0.1f,0.1f,
                         -0.25f,0.1f,-0.1f,
                         -0.25f,0.1f,0.1f,
                         -0.25f,-0.1f,-0.1f,
                         -0.25f,-0.1f,0.1f,
                         -0.1f,-0.1f,-0.1f,
                         -0.1f,-0.1f,0.1f,
                         -0.1f,-0.25f,-0.1f,
                         -0.1f,-0.25f,0.1f,
                         0.1f,-0.25f,-0.1f,
                         0.1f,-0.25f,0.1f,
                         0.1f,-0.1f,-0.1f,
                         0.1f,-0.1f,0.1f,
                         0.25f,-0.1f,-0.1f,
                         0.25f,-0.1f,0.1f,
                         0.25f,0.1f,-0.1f,
                         0.25f,0.1f,0.1f,
                         0.1f,0.1f,-0.1f,
                         0.1f,0.1f,0.1f,
                         0.1f,0.25f,-0.1f,
                         0.1f,0.25f,0.1f,
                         -0.1f,0.25f,-0.1f,
                         -0.1f,0.25f,0.1f
        };

        frontBuffer=BufferFactory.MakeFloatBuffer(front);
        backBuffer=BufferFactory.MakeFloatBuffer(back);
        blanketBuffer=BufferFactory.MakeFloatBuffer(blanket);

        color=new MyColor();
        color.setAmbient(new float[]{0.0f,1.0f,0.0f,0.8f});
        color.setDiffuse(new float[]{0.0f,1.0f,0.0f,0.8f});
        color.setSpecular(new float[]{0.6f,0.6f,0.6f,0.7f});
        color.setEmission(new float[]{0.1f,0.1f,0.1f,0.6f});
        color.setShininess(1.0f);
    }

    @Override
    public void draw(GL10 gl){
        transform(gl);

        OpenGLSystem.enable(gl,OpenGLSystem.CULL_FACE | OpenGLSystem.BLEND_IF_NO_FOG);
        OpenGLSystem.enableClientStates(gl,OpenGLSystem.NORMAL_ARRAY | OpenGLSystem.VERTEX_ARRAY);

        OpenGLSystem.setMaterial(gl,color);

        OpenGLSystem.drawTriangles(gl,null,frontBuffer,frontBuffer,
                null,14,GL10.GL_TRIANGLE_FAN);
        OpenGLSystem.drawTriangles(gl,null,blanketBuffer,blanketBuffer,
                null,26,GL10.GL_TRIANGLE_STRIP);
        OpenGLSystem.drawTriangles(gl,null,backBuffer,backBuffer,
                null,14,GL10.GL_TRIANGLE_FAN);

        OpenGLSystem.disableClientStates(gl,OpenGLSystem.NORMAL_ARRAY | OpenGLSystem.VERTEX_ARRAY);
        OpenGLSystem.disable(gl,OpenGLSystem.CULL_FACE | OpenGLSystem.BLEND);
    }
}
